package com.example.ch07_01_01listview;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
private ListView lv;
private String[] color;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initHendler();
	}

	private void initHendler() {
		// TODO Auto-generated method stub
		ArrayAdapter adapt=new ArrayAdapter(this,android.R.layout.simple_list_item_1,color);
		lv.setAdapter(adapt);
		lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				String select=arg0.getItemAtPosition(arg2).toString();
				Toast.makeText(MainActivity.this, select, Toast.LENGTH_SHORT).show();
				return false;
			}
		
		});
	}

	private void initView() {
		// TODO Auto-generated method stub
		lv=(ListView)this.findViewById(R.id.listView1);
		color=getResources().getStringArray(R.array.colors);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
